package com.zenithmind.article.pojo.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;



/**
 * 用户视图对象
 * 遵循单一职责原则：专注于用户展示数据
 * 遵循里氏替换原则：正确继承BaseVO
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Schema(name = "用户视图对象", description = "用户展示数据对象")
public class UserVO extends BaseVO {

    @Schema(description = "用户名")
    private String username;

    @Schema(description = "邮箱")
    private String email;

    @Schema(description = "手机号")
    private String phone;

    @Schema(description = "头像URL")
    private String avatar;

    @Schema(description = "个人介绍")
    private String introduction;

    @Schema(description = "已使用存储空间")
    private long storageUsed;

    @Schema(description = "存储空间限制")
    private long storageLimit;

    @Schema(description = "用户角色")
    private String role;

    @Override
    public String getDisplayName() {
        return username != null ? username : "未知用户";
    }

    /**
     * 获取显示头像
     */
    public String getDisplayAvatar() {
        return avatar != null && !avatar.trim().isEmpty() ? avatar : "/default-avatar.png";
    }

    /**
     * 获取脱敏手机号
     */
    public String getMaskedPhone() {
        if (phone == null || phone.length() < 11) {
            return phone;
        }
        return phone.substring(0, 3) + "****" + phone.substring(7);
    }

    /**
     * 获取脱敏邮箱
     */
    public String getMaskedEmail() {
        if (email == null || !email.contains("@")) {
            return email;
        }
        String[] parts = email.split("@");
        if (parts[0].length() <= 2) {
            return email;
        }
        return parts[0].substring(0, 2) + "***@" + parts[1];
    }

    /**
     * 获取存储使用率
     */
    public double getStorageUsageRate() {
        if (storageLimit <= 0) {
            return 0.0;
        }
        return (double) storageUsed / storageLimit * 100;
    }

    /**
     * 检查存储是否已满
     */
    public boolean isStorageFull() {
        return storageUsed >= storageLimit;
    }
}
